package com.fulu.game.bi.controller.auth;

import com.fulu.game.bi.common.controller.BaseController;
import com.fulu.game.bi.entity.po.auth.BiRole;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.auth.role.RoleQueryVO;
import com.fulu.game.bi.entity.vo.auth.role.RoleSaveVO;
import com.fulu.game.bi.redis.service.auth.BiRoleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色管理
 */
@RestController
@RequestMapping("/api/v1/role")
@Slf4j
public class RoleController extends BaseController {

    @Autowired
    private BiRoleService biRoleService;

    /**
     * 查询角色列表
     */
    @PostMapping("/list")
    public Result<Page<BiRole>> list(RoleQueryVO vo) {
        PageInfo<BiRole> page = biRoleService.list(vo);

        return Result.success().data(page).msg("查询成功");
    }

    /**
     * 新增角色
     */
    @PostMapping("/save")
    public Result<BiRole> save(RoleSaveVO vo) {
        BiRole role = biRoleService.save(vo);

        return Result.success().data(role).msg("保存成功");
    }

    /**
     * 查询单个角色
     */
    @PostMapping("/query")
    public Result<BiRole> findById(@RequestParam("id") Integer id) {
       BiRole role =  biRoleService.findById(id);

       return Result.success().data(role).msg("查询成功");
    }

    /**
     * 删除角色
     */
    @PostMapping("/del")
    public Result delete(@RequestParam("id") Integer id) {
        biRoleService.deleteById(id);

        return Result.success().msg("删除成功");
    }


}
